﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NEATlib;
using TimbreRecognition.Recognition.Model.Kohenen;

namespace TimbreRecognition.Recognition.Helper
{
    public class NeuronNetworkHelper
    {
        public static void CalculeteWinCountForEachClass(KohenenNetwork network, List<DataItem> features)
        {
            network.ResetWinCountForClasses();

            foreach (DataItem item in features)
            {
                network.recalculateOutput(item.DataSeries);
                KohenenNeuron neuron = network.getWinner();
                double[] classInfo = item.ExpectedOutput;
                int classIndex = Array.IndexOf(classInfo, classInfo.Where(o => o == 1).Single());
                neuron.IncWinCountForClass(classIndex);
            }
        }

        public static void CalculeteWinCount(KohenenNetwork network, IEnumerable<double[]> data)
        {
            network.resetWinCount();

            foreach (double[] values in data)
            {
                network.recalculateOutput(values);
                KohenenNeuron neuron = network.getWinner();
                neuron.incWinCount();
            }
        }
    }
}
